<?php

namespace Cck\ArticlesSystem\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UserStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nickname' => [
                'bail',
                'required',
                'max:25',
                Rule::unique('users', 'nickname')
            ],
            'email' => [
                'bail',
                'required',
                'max:255',
                'email',
                Rule::unique('users', 'email')
            ],
            'password' => [
                'bail',
                'required',
                'min:6',
                'confirmed',
            ],
            'roles' => 'array',
            'roles.*' => [
                'required',
                'integer',
                'distinct',
                Rule::exists('roles', 'id')
            ]
        ];
    }
}
